const service = require('../service/comment.service');
class CommentController {
  async create (ctx, next) {
   try {
    const { id } = ctx.user;
    const { content, momentId } = ctx.request.body; 
    const result = await service.create(momentId, content, id);
    ctx.body = result;
   } catch (err) {
    console.log(err);
   }
  }
  async reply (ctx, next) {
    try {
      const { id } = ctx.user;
      const { content, momentId } = ctx.request.body; 
      const { commentId } = ctx.params;
      const result = await service.reply(momentId, content, id, commentId);
      ctx.body = result;
    } catch (err) {
      console.log(err);
    }
  }
  async update (ctx, next) {
    const { commentId } = ctx.params;
    const { content } = ctx.request.body;
    const result = await service.update(commentId, content)
    ctx.body = result;
  }
  async remove (ctx, next) {
    console.log('remove');
    const { commentId } = ctx.params;
    const result = await service.remove(commentId);
    ctx.body = result;
  }
  async list (ctx, next) {
    const { momentid } = ctx.query;
    const result = await service.getCommentsByMomentId(momentid)
    ctx.body = result;
  }
}


module.exports = new CommentController();